package testsuite_homepage;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import testsuite_homepage.pageobject.LoggedInHomepage;

public class LoginForm {
	private final WebDriver driver;
    
    private By loginformLocator = By.id("form-login");
private By usernameLocator = By.id("modlgn_username");
private By passwordLocator = By.id("modlgn_passwd");
private By loginButtonLocator = By.name("Submit");

public LoginForm(WebDriver driver) {
    this.driver = driver;
   
    if (!driver.findElement(loginformLocator).isDisplayed()) {
        throw new IllegalStateException("There is no login form");
    }
}

public LoginForm typeUsername(String username) {
   
    driver.findElement(usernameLocator).sendKeys(username);

    return this;    
}

public LoginForm typePassword(String password) {
   
    driver.findElement(passwordLocator).sendKeys(password);
    return this;    
}

public LoggedInHomepage submitLogin() {
   
    driver.findElement(loginButtonLocator).submit();
    return new LoggedInHomepage(driver);    
}

public FalseLoginHomepage submitFalseLogin() {
   
    driver.findElement(loginButtonLocator).submit();
    return new FalseLoginHomepage(driver);  
}

public LoggedInHomepage loginAs(String username, String password) {
    typeUsername(username);
    typePassword(password);
    return submitLogin();
}


}
